package com.yanqu.road.server.cmd.union.cross.huaben;

import com.yanqu.road.pb.union.cross.UnionHuaBenProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_UNION_HUA_BEN_RANK, desc = "话本排行")
public class UnionHuaBenUnionWeekRankListCmd extends AbstractCommand {

    int type;

    int degree;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionHuaBenProto.UnionHuaBenUnionWeekRankListReqMsg reqMsg = UnionHuaBenProto.UnionHuaBenUnionWeekRankListReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        degree = reqMsg.getDegree();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(type != 0 && type != 1){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        player.sendPacket(Protocol.C_CROSS_UNION_HUA_BEN_RANK, UnionHuaBenProto.UnionHuaBenUnionWeekRankListReqMsg.newBuilder().setType(type).setDegree(degree));
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_CROSS_UNION_HUA_BEN_RANK, UnionHuaBenProto.UnionHuaBenUnionWeekRankListRespMsg.newBuilder().setRet(ret).setDegree(degree).setType(type));
        }
    }
}
